<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Dell
  Date: 2018/12/19
  Time: 17:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增菜单信息</title>
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css"  media="all">
    <script language="javascript" type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>
</head>
<body margintop="100px">



<form id="menuForm" name="menuForm" class="layui-form" action="" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">菜单名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="name" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单URL</label>
        <div class="layui-input-inline">
            <input type="text" name="url" lay-verify="url" autocomplete="off" placeholder="" class="layui-input layui-form-danger" value="">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">父级菜单</label>
        <div class="layui-input-inline">
            <select name="high" lay-filter="aihao">
                <option value=""></option>
                <option value="100">顶级菜单</option>
                <c:forEach var="l" items="${requestScope.menus}">
                    <option value="${l.meId}">${l.meName}</option>
                </c:forEach>

            </select><div class="layui-unselect layui-form-select">

        </div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">菜单状态</label>
        <div class="layui-input-block">
            <input type="checkbox" checked="" name="rool" lay-skin="switch" lay-filter="switchTest" lay-text="使用|禁用">
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="" lay-filter="demo1">添加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>



</form>



</body>
<script src="../../js/jquery.min.3.1.0.js"></script>
<script src="../../layuiadmin/layui/layui.js" charset="utf-8"></script>

<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');

        //自定义验证规则
        form.verify({
            name: [
                /^[\u4e00-\u9fa5]{3,}$/
                ,'菜单名称必须为3位以上的中文字符'
            ]
            ,url:function (value) {
                if(value==""){
                    return '菜单URL不能为空！';
                }
            }
        });



        //监听提交
        form.on('submit(demo1)', function(data){
            var index = parent.layer.getFrameIndex(window.name);

            $.ajax({
                url:"/MenuAddServlet",   //请求路径
                datatype:"json",//返回的格式
                data:$("#menuForm").serialize(), //参数
                type:"post", //什么请求
                success:function (data) { //请求成功以后
                    //AJAX成功以后返回的
                    var obj = eval('(' + data + ')');
                    layer.msg(obj.msg);

                    //延时500ms关闭窗口
                    setTimeout(function () {
                        parent.layer.close(index);
                    }, 500);
                }
            });


            return false;
        });




    });
</script>
</html>

